package com.ruoyi.project.system.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysDate;
import com.ruoyi.project.system.service.ISysDateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/system/date")
public class SysDateController extends BaseController {
    @Autowired
    private ISysDateService dateService;

    @GetMapping("/selectDateList/{yearorMonth}")
    public AjaxResult selectDateList(@PathVariable("yearOrMonth") String yearOrMonth)
    {
        return AjaxResult.success(dateService.selectDateList(yearOrMonth));
    }

    @PostMapping("")
    public AjaxResult insert(@RequestBody SysDate date)
    {
//        Date startDate = DateUtils.dateTime("yyyy-MM-dd", "2025-01-01");
//        do{
//            SysDate sysDate = new SysDate();
//            sysDate.setDate(startDate);
//            System.out.println("================== 日期：" + DateUtils.parseDateToStr("yyyy-MM-dd", startDate));
//            dateService.insertDate(sysDate);
//            startDate = DateUtils.addDays(startDate, 1);
//        }while ("2025".equals(DateUtils.parseDateToStr("yyyy", startDate)));


        return toAjax(dateService.insertDate(date));
    }

    @PutMapping("")
    public AjaxResult update(@RequestBody SysDate date)
    {
        return toAjax(dateService.updateDate(date));
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id)
    {
        return toAjax(dateService.deleteDate(id));
    }
}
